package vn.game;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import vn.game.R;
public class InputWords extends Activity {

	EditText edtWords;
	EditText edtHint;
	RadioButton rdAccross;
	int postion;
	Button btnCancel;
	Button btnAdd;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.input_wrods);
		try {
			edtWords = (EditText) findViewById(R.id.edtWords);
			edtHint = (EditText) findViewById(R.id.edtHint);
			rdAccross = (RadioButton) findViewById(R.id.rdAcross);

			Intent intent = getIntent();
			postion = intent.getIntExtra("location", 0);

			btnAdd = (Button) findViewById(R.id.btnAdd);
			btnAdd.setOnClickListener(new OnClickListener() {
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					try {
						if (checkValue()) {
							Intent data = new Intent();
							if (rdAccross.isChecked() == true)
								data.putExtra("orientation", true);
							else
								data.putExtra("orientation", false);
							data.putExtra("postion", postion);
							data.putExtra("words", edtWords.getText().toString().trim().toUpperCase());
							data.putExtra("hint", edtHint.getText().toString().trim());

							setResult(RESULT_OK, data);
							finish();
						}
					} catch (Exception ex) {
						Log.i("InputWord.onCreate", "Error: " + ex.getMessage());
					}
				}
			});

			btnCancel = (Button) findViewById(R.id.btnCancel);
			btnCancel.setOnClickListener(new OnClickListener() {

				public void onClick(View v) {
					// TODO Auto-generated method stub
					finish();
				}
			});

		} catch (Exception ex) {
			Log.i("InputWords.onCreate", "Error: " + ex.getMessage());
		}

	}

	private boolean checkValue() {
		if (edtWords.getText().toString().trim().equals("")) {
			Toast.makeText(this, "Enter Word", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (edtHint.getText().toString().trim().equals("")) {
			Toast.makeText(this, "Enter Hint", Toast.LENGTH_SHORT).show();
			return false;
		}

		return true;
	}

	@Override
	public void finish() {
		try {
			super.finish();
		} catch (Exception ex) {
			Log.i(" Inputwords.finish: ", ex.getMessage());
		}
	}

}
